package com.example.prototype;

import lombok.Data;

import java.io.*;
import java.util.List;

/**
 * Created by fjx on 2021/6/17
 */
@Data
public class Person implements Cloneable, Serializable {

    public Person() {
        System.out.println("构造中。。");
    }

    private Integer id;

    private String name;

    private List<String> clazz;

    @Override
    protected Person clone() throws CloneNotSupportedException {
        return (Person) super.clone();
    }

    public Person deepClone(){
        // 输出
        try {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            ObjectOutputStream oos = new ObjectOutputStream(baos);
            oos.writeObject(this);

            // 输入
            ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
            ObjectInputStream ois = new ObjectInputStream(bais);
            Person person = (Person) ois.readObject();
            return person;
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }

    }
}
